package hutech.ksv.view;

import hutech.ksv.entity.NhaTroEntity;
import hutech.ksv.entity.ThongTinTuyenDungEntity;
import hutech.ksv.model.ThongTinTDDataModel;
import hutech.ksv.service.TTTuyenDungService;
import hutech.ksv.service.Utilities;

import java.io.Serializable;
import java.sql.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("thongTinTuyenDungManagedBean")
@Scope("session")
public class TTTuyenDungManageBean implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Autowired
	TTTuyenDungService tttdService;
	
	@Autowired
	Utilities utilities;
	
	private int maTTTD;
	private String ngayLapTTTD;
	private String tongSoLuongTD;
	private String ngayBatDauTD;
	private String ngayKetThucTD;
	private boolean trangThaiTTTD;
	private boolean trangThaiDuyetTTTD;
	private String tenTKCT;
	private String tenTKQTV;
	private ThongTinTDDataModel ttTDListDataModel;
	
	public ThongTinTDDataModel getTtTDListDataModel() {
		return ttTDListDataModel;
	}
	public void setTtTDListDataModel(ThongTinTDDataModel ttTDListDataModel) {
		this.ttTDListDataModel = ttTDListDataModel;
	}
	public int getMaTTTD() {
		return maTTTD;
	}
	public void setMaTTTD(int maTTTD) {
		this.maTTTD = maTTTD;
	}
	public String getNgayLapTTTD() {
		return ngayLapTTTD;
	}
	public void setNgayLapTTTD(String ngayLapTTTD) {
		this.ngayLapTTTD = ngayLapTTTD;
	}
	public String getNgayBatDauTD() {
		return ngayBatDauTD;
	}
	public void setNgayBatDauTD(String ngayBatDauTD) {
		this.ngayBatDauTD = ngayBatDauTD;
	}
	public String getNgayKetThucTD() {
		return ngayKetThucTD;
	}
	public void setNgayKetThucTD(String ngayKetThucTD) {
		this.ngayKetThucTD = ngayKetThucTD;
	}
	public boolean isTrangThaiTTTD() {
		return trangThaiTTTD;
	}
	public void setTrangThaiTTTD(boolean trangThaiTTTD) {
		this.trangThaiTTTD = trangThaiTTTD;
	}
	public boolean isTrangThaiDuyetTTTD() {
		return trangThaiDuyetTTTD;
	}
	public void setTrangThaiDuyetTTTD(boolean trangThaiDuyetTTTD) {
		this.trangThaiDuyetTTTD = trangThaiDuyetTTTD;
	}
	public String getTenTKCT() {
		return tenTKCT;
	}
	public void setTenTKCT(String tenTKCT) {
		this.tenTKCT = tenTKCT;
	}
	public String getTenTKQTV() {
		return tenTKQTV;
	}
	public void setTenTKQTV(String tenTKQTV) {
		this.tenTKQTV = tenTKQTV;
	}
	
	public String getTongSoLuongTD() {
		return tongSoLuongTD;
	}
	public void setTongSoLuongTD(String tongSoLuongTD) {
		this.tongSoLuongTD = tongSoLuongTD;
	}
	public void onLoad(){
		List<ThongTinTuyenDungEntity> danhSachTTTD = tttdService.loadThongTinTD();
		ttTDListDataModel = new ThongTinTDDataModel(danhSachTTTD);
	}
	
	public void reLoad() {
		this.maTTTD = 0;
		this.tongSoLuongTD = "0";
		this.trangThaiTTTD = false;
		this.trangThaiDuyetTTTD = false;
		this.tenTKCT = "";
		this.tenTKQTV = "";
	}
	
	public String insert() {
		ThongTinTuyenDungEntity tttd = new ThongTinTuyenDungEntity();
		tttd.setNgayLapTTTD(utilities.convertFromStringToDate(ngayLapTTTD));
		tttd.setTongSoLuongTD(Integer.valueOf(tongSoLuongTD));
		tttd.setNgayBatDauTD(utilities.convertFromStringToDate(ngayBatDauTD));
		tttd.setNgayKetThucTD(utilities.convertFromStringToDate(ngayKetThucTD));
		tttd.setTrangThaiTTTD(trangThaiTTTD);
		tttd.setTrangThaiDuyetTTTD(trangThaiDuyetTTTD);
		tttd.setTenTKCT(tenTKCT);
		tttd.setTenTKQTV(tenTKQTV);
		tttdService.insertTTTuyenDung(tttd);
		return "";
	}
	
	public String update() {
		ThongTinTuyenDungEntity tttd = new ThongTinTuyenDungEntity();
		tttd.setNgayLapTTTD(utilities.convertFromStringToDate(ngayLapTTTD));
		tttd.setTongSoLuongTD(Integer.valueOf(tongSoLuongTD));
		tttd.setNgayBatDauTD(utilities.convertFromStringToDate(ngayBatDauTD));
		tttd.setNgayKetThucTD(utilities.convertFromStringToDate(ngayKetThucTD));
		tttd.setTrangThaiTTTD(trangThaiTTTD);
		tttd.setTrangThaiDuyetTTTD(trangThaiDuyetTTTD);
		tttd.setTenTKCT(tenTKCT);
		tttd.setTenTKQTV(tenTKQTV);
		tttdService.updateTTTuyenDung(tttd);
		return "";
	}
	
	public List<ThongTinTuyenDungEntity> loadThongTinTD() {
		return tttdService.loadThongTinTD();
	}
	
	public String edit() {
		ThongTinTuyenDungEntity ttTDEntity = new ThongTinTuyenDungEntity();
		ttTDEntity = ttTDListDataModel.getRowData();
		maTTTD = ttTDEntity.getMaTTTD();
		ngayLapTTTD = String.valueOf(ttTDEntity.getNgayLapTTTD());
		tongSoLuongTD = String.valueOf(ttTDEntity.getTongSoLuongTD());
		ngayBatDauTD = String.valueOf(ttTDEntity.getNgayBatDauTD());
		ngayKetThucTD = String.valueOf(ttTDEntity.getNgayKetThucTD());
		trangThaiTTTD = ttTDEntity.isTrangThaiTTTD();
		trangThaiDuyetTTTD = ttTDEntity.isTrangThaiDuyetTTTD();
		tenTKCT = ttTDEntity.getTenTKCT();
		tenTKQTV = ttTDEntity.getTenTKQTV();
		return "updateTTTD";
		// return "testNavigate";
	}
}
